/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.unitn.science.matr155863_148346_145963.bccastestore.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author berto
 */
public class Crypto {
    
    public static String SHA_512="SHA-512";
    public static String SHA_256="SHA-256";
    public static String MD5="MD5";
    public static String SHA="SHA";
    public static String SHA_1="SHA-1";
    public static String SHA_384="SHA-384";
    
    
    public static String crypto(String message){
        MessageDigest md;
        String crypto=null;
        try {
            md= MessageDigest.getInstance(Crypto.SHA_256);
            md.update(message.getBytes());
            byte[] mb = md.digest();
            crypto = "";
            for (int i = 0; i < mb.length; i++) {
                byte temp = mb[i];
                String s = Integer.toHexString(new Byte(temp));
                while (s.length() < 2) {
                    s = "0" + s;
                }
                s = s.substring(s.length() - 2);
                crypto += s;
            }
            //System.out.println(out.length());
            //System.out.println("CRYPTO: " + out);
 
        } catch (NoSuchAlgorithmException e) {
            System.out.println("ERROR: " + e.getMessage());
            crypto=null;
        } 
        return crypto;
    }
    
    public static void main(String args[]){
        String psws[]={"psw1",
                        "psw2",
                        "psw3",
                        "psw4",
                        "psw5",
                        "psw6",
                        "psw7",
                        "psw8",
                        "psw9",
                        "psw10",
                        "psw11",
                        "psw12",
                        "admin"};
        for(String p:psws){
            String newP=crypto(p);
            System.out.println(newP);
        }
    }
}
